#pragma once
#include "RecvLine.h"
#include <string.h>
#include <stdio.h>
#include <afxwin.h>
#include <afxcmn.h>
#include <afxshelllistctrl.h>

class RequestHandle
	:public RecvLine
{
public:
	RequestHandle(void);
	virtual ~RequestHandle(void);

	void SetState(int state);
	int GetState(void) { return m_nState; }
	void Close(void);
	void HaveResponse(void);
	void SetDirList(CListCtrl *pList) { m_pkDirList = pList; }
	void SetFileList(CListCtrl *pList) { m_pkFileList = pList; }
	void SetHomeList(CMFCShellListCtrl *pShellList) { m_pkHomeList = pShellList; }
	void SetFileName(char *fn, UINT len);
	void SetSock(SOCKET s) { m_nConn = s; }
	void SetIP(char *ip);

protected:
	virtual int ResponseAnalysis(void) = 0;
	virtual void ResponsePWD(void);
	void ResponsePASV(void);
	void SetDataPort(void);
	void CreateDataConn(void);
	void PutItemList(void);
	//variables
	SOCKET m_nDataConn;
	SOCKADDR_IN m_kSockAddr;
	int m_nState;
	int m_nFileSize;
	char m_cSendBuf[CustomBuf::SYNBUFSIZE + 1];
	char m_cServPath[CustomBuf::SYNBUFSIZE + 1];
	char m_cIP[CustomBuf::SMALLBUF + 1];
	char m_cNameBuf[CustomBuf::BIGBUF + 1];
	char m_cFileName[CustomBuf::SYNBUFSIZE + 1];
	char m_cSizeBuf[CustomBuf::SMALLBUF + 1];
	RecvLine *m_pkDataRecv;
	CListCtrl *m_pkDirList;
	CListCtrl *m_pkFileList;
	CMFCShellListCtrl *m_pkHomeList;

private:
	uint16 m_DataPort;
	char *ToWhiteSpace(char *p);
	char *PassWhiteSpace(char *p);
	char *FileSave(char *p);
	char *DirectorySave(char *p);
	void SaveName(char *p);
};

